package com.sugon.controller;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.SysKnowTypeEntity;
import com.sugon.service.SysKnowTypeService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 知识类型Controller
 *
 * @author sugon
 * @date 2019-11-27 09:48:04
 * @modified 2020-7-01 16:50 YuXD
 * 新增 /sysknowtype/optionList接口
 */
@Controller
@RequestMapping("sysknowtype")
public class SysKnowTypeController {
    @Autowired
    private SysKnowTypeService sysKnowTypeService;

    /**
     * 获取知识类型下拉列表用到的数据
     */
    @RequestMapping("/optionList")
    @ResponseBody
    public R optionList() {
        return R.ok().put("optionList", sysKnowTypeService.listAll());
    }

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sysknowtype:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<SysKnowTypeEntity> sysKnowTypeList = sysKnowTypeService.queryList(query);
        int total = sysKnowTypeService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(sysKnowTypeList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sysknowtype:info")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        SysKnowTypeEntity sysKnowType = sysKnowTypeService.queryObject(id);

        return R.ok().put("sysKnowType", sysKnowType);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sysknowtype:save")
    @ResponseBody
    public R save(@RequestBody SysKnowTypeEntity sysKnowType) {
        sysKnowTypeService.save(sysKnowType);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sysknowtype:update")
    @ResponseBody
    public R update(@RequestBody SysKnowTypeEntity sysKnowType) {
        sysKnowTypeService.update(sysKnowType);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sysknowtype:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        sysKnowTypeService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<SysKnowTypeEntity> list = sysKnowTypeService.queryList(params);

        return R.ok().put("list", list);
    }
}
